package com.weng.coder.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weng.coder.entity.ProjectUser;
import com.weng.coder.mapper.ProjectUserMapper;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.beans.Transient;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 项目用户 业务实现类
 *
 * @author wengzhonghui
 * @创建时间 2018-07-17 17:22:12
 *
 */
@Service("projectUserService")
public class ProjectUserServiceImpl extends BaseServiceImpl<ProjectUserMapper, ProjectUser> implements  ProjectUserService {
	@Resource
	private ProjectUserMapper projectUserDao;
	

	
	@Override
	public List<ProjectUser> findByIds(List<String> ids){

		return   projectUserDao.selectBatchIds(ids);
	}
	/**
	 * Save
	 * @param t
	 */
	@Override
	public boolean save(ProjectUser t) {
			if(StringUtils.isEmpty(t.getId())){
					projectUserDao.insert(t);
			}else{
					projectUserDao.updateById(t);
			}
			return true;
	}

	@Override
	public void delete(String id) {
		projectUserDao.deleteById(id);
	}





	


	

	@Override
	public void delete(ProjectUser t) {
		projectUserDao.deleteById(t.getId());
	}
	

	@Override
	public ProjectUser getOne(String id) {
		return projectUserDao.selectById(id);
	}





	@Override
	public void deleteByIds(String[] ids) {
		if(ids!=null && ids.length>0){
			for(String id:ids){
				projectUserDao.deleteById(id);
			}
		}
	}
	
	@Override
	public int deleteByProjectId(String projectId){
		QueryWrapper<ProjectUser> qw = new QueryWrapper<>();
		qw.eq("PROJECT_ID",projectId);
		return this.projectUserDao.delete(qw);
	}
	
	@Override
	public List<ProjectUser> findByProjectIdAndUserId(String projectId, String userId){
		QueryWrapper<ProjectUser> qw = new QueryWrapper<>();
		qw.eq("PROJECT_ID",projectId);
		qw.eq("USER_ID", userId);
		return projectUserDao.selectList(qw);
	}
	
	@Override
	public int countByProjectIdAndUserIdAndIsOwner(String projectId,String userId,Integer isOwner){
		QueryWrapper<ProjectUser> qw = new QueryWrapper<>();
		qw.eq("PROJECT_ID",projectId);
		qw.eq("USER_ID", userId);
		qw.eq("IS_OWNER", isOwner);
		return projectUserDao.selectCount(qw);
	}
	
}
